package utils;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import cn.hutool.http.HttpUtil;

/**
 * @author: chenjiang
 * @description: TODO
 * @date: 2022/7/17 2:12 PM
 */
public class FileUtils {

    //
    // public void testCraw() throws IOException {
    //     final WebClient webClient = new WebClient(BrowserVersion.BEST_SUPPORTED);
    //     webClient.getOptions().setThrowExceptionOnScriptError(false);
    //
    //     // webClient.waitForBackgroundJavaScriptStartingBefore(5000);
    //     webClient.getOptions().setTimeout(10000);
    //     webClient.getOptions().setJavaScriptEnabled(true);
    //     webClient.getOptions().setCssEnabled(false);
    //     webClient.getOptions().setRedirectEnabled(true);
    //     webClient.getOptions().setUseInsecureSSL(false);
    //     webClient.getOptions().setThrowExceptionOnFailingStatusCode(false);
    //     webClient.getCookieManager().setCookiesEnabled(true);
    //     webClient.setAjaxController(new NicelyResynchronizingAjaxController());
    //
    //
    //     final List<String> list = new ArrayList<>();
    //
    //     new WebConnectionWrapper(webClient) {
    //         @Override
    //         public WebResponse getResponse(final WebRequest request) throws IOException {
    //             final WebResponse response = super.getResponse(request);
    //             list.add("urllook="+request.getHttpMethod()+ " " + request.getUrl());
    //             return response;
    //         }
    //     };
    //
    //     webClient.getPage("https://youku.com/");
    //     webClient.waitForBackgroundJavaScript(20_000);
    //     webClient.setJavaScriptTimeout(20_000);
    //     list.forEach(System.out::println);
    // }

    public static void main(String[] args) throws InterruptedException {
        String name = "ethan";
        String urlFormat = "https://gramener.com/comicgen/v1/comic?name="+name+"&angle=%s&pose=%s&emotion=%s&box=&boxgap=&mirror=mirror&ext=%s";
        String[] angles={
            "side" ,
            "straight"
        };

        String[] poses = {
            //bean
            // "angry",
            // "handsfolded",
            // "handsonhip",
            // "holdingbook",
            // "holdinglaptop",
            // "pointingright",
            // "pointingup",
            // "readingpaper",
            // "shrug",
            // "super",
            // "thinking",
            // "thumbsup",
            // "yuhoo"

            //ethan
            "explaining45degrees",
            "holdingstick",
            "normal",
            "pointingatboard",
            "pointingright",
            "pointingrightat45degrees",
            "righthandpointing"

        };
        String[] emotions = {
            //bean
            // "angry",
            // "annoyed",
            // "blush",
            // "cry",
            // "curious",
            // "hmm",
            // "lookingdown",
            // "lookingup",
            //
            // "neutral",
            // "sad",
            // "shocked",
            // "shout",
            // "smile",
            // "tired",
            // "wink",
            // "worried",
            // "yuhoo"


            //ethan
            "angry",
            "afraid",
            "cry",
            "cryingloudly",
            "curious",
            "excited",


            "happy",
            "irritated",
            "lookingdown",
            "lookingup",
            "ooh",


            "neutral",
            "rollingeyes",

            "sad",
            "shocked",
            "shout",
            "smile",
            "wink",
            "smirk"
        };

        String[] exts = {
             "svg",
            "png"
        };
        for(String angle:angles){
            for(String pose:poses){
                for(String emotion:emotions){
                    for(String ext:exts){
                        String url = String.format(urlFormat,angle,pose,emotion,ext)+"&boxcolor=%23000000";
                        String fileName = "/Users/jiangchen/Documents/comic/"+name+"/"+angle+"/"+pose+"_"+emotion+"."+ext;
                        HttpUtil.downloadFile(url,fileName);
                        System.out.println("download file ="+fileName);
                        Thread.sleep(500);
                    }
                }
            }
        }

    }
}
